package com.faithbj.webservice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.jws.WebService;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.faithbj.common.model.compare.AFMOfficalData;
import com.faithbj.common.utils.DateUtils;
import com.faithbj.service.CompareService;
import com.faithbj.support.vo.AFMCompareResponse;
import com.faithbj.support.vo.AFMCompareResponse.AFMData;
import com.faithbj.support.vo.CivilCompareResponse;
import com.faithbj.support.vo.CompareRequest;
import com.faithbj.support.vo.CompareResponse;
import com.faithbj.support.vo.HPCompareResponse;
import com.faithbj.support.vo.IBACompareResponse;
import com.faithbj.support.vo.PSCompareResponse;
import com.faithbj.support.vo.SICompareResponse;
import com.faithbj.support.vo.TaxCompareResponse;
import com.faithbj.webservice.test.User;
import com.faithbj.webservice.test.Wraper;

/**
 * webservice 实现类
 * 
 * @author chen liu
 */
@WebService(endpointInterface = "com.faithbj.webservice.WebServiceServer")
@Service("webServiceBean")
public class WebServiceServerImpl implements WebServiceServer {
    @Resource
    private CompareService compareService;

    @Override
    public boolean sendRequest(List<CompareRequest> requestList) {
        for (CompareRequest request : requestList) {
            System.out.println(request);
        }
        return true;
    }

    @Override
    public boolean sendResponse(List<AFMCompareResponse> responseList) {
        if (responseList != null) {
            for (AFMCompareResponse response : responseList) {
                handleAFMResponse(response);
            }
        }
        return true;
    }

    private void handleAFMResponse(CompareResponse response) {
        AFMCompareResponse afmResponse = (AFMCompareResponse) response;
        List<AFMOfficalData> updateList = compareService.getAFMOfficalDataForUpdate(afmResponse.getBatchNum(),
                afmResponse.getDepartmentNum(), afmResponse.getMainApplicantCardId());
        System.out.println(updateList.size());
        if (updateList != null) {
            for (AFMOfficalData data : updateList) {
                for (AFMData resData : afmResponse.getMemberDatas()) {
                    System.out.println(data.getApplicantCardNum());
                    System.out.println(resData.getApplicantCardNum());
                    if (data.getApplicantCardNum().equals(resData.getApplicantCardNum())) {
                        System.out.println(data.getApplicantCardNum());
                        BeanUtils.copyProperties(resData, data);
                        data.setIsQueryReturned(1);
                        data.setQueryReturnDt(DateUtils.getCurrentDate());
                        compareService.saveOrUpdateAFMOfficalData(data);
                        break;
                    }
                }
            }
        }
    }

    private void handleCivilResponse(CompareResponse response) {

    }

    private void handleIBAResponse(CompareResponse response) {

    }

    private void handlePSResponse(CompareResponse response) {

    }

    private void handleSIResponse(CompareResponse response) {

    }

    private void handleHPResponse(CompareResponse response) {

    }

    private void handleTaxResponse(CompareResponse response) {

    }
}
